<?php 
$sec=$this->input->get('sec',TRUE);
$one=$this->input->get('one',TRUE);
if(empty($_GET['sec']) && empty($_GET['one'])){
	$con=$this->db->get_where('coltypes',array('cid'=>4,'depth'=>0))->result_array();
	if(!empty($con)){
		$nav=$this->db->order_by('sort_id','asc')->get_where('coltypes',array('cid'=>4,'fid'=>$con[0]['id'],'depth'=>1))->result_array();
		if(!empty($nav)){
			$sec=$nav[0]['id'];
			$page=!empty($_GET['p'])?$_GET['p']:1;
			$this->load->library('pagination');
			$config['base_url'] =SITE_URL.('product_ajax?sec='.$sec);
			$where=array('audit'=>1,'ctype'=>$sec,'cid'=>4);
			$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
			$config['per_page'] = 12;
			$config['uri_segment'] = 3;//页码所在URI段
			//将链接改为get方式
			$config['enable_query_strings']=TRUE;
			$config['page_query_string']=TRUE;
			$config['use_page_numbers'] = TRUE;
			$config['cur_tag_open']= '<a class="active">';
			$config['cur_tag_close']='</a>';
			$config['full_tag_open'] = '<div class="page">';
			$config['full_tag_close'] = '</div>';

			$config['num_links']=5;
			$config['prev_link']='<';
			$config['next_link']='>';
			$config['num_tag_open']='';
			$config['num_tag_close']='';
			$config['prev_tag_open']='';
			$config['prev_tag_close']='';
			$config['next_tag_open']='';
			$config['next_tag_close']='';
			$config['last_link'] = false;
			$config['first_link']= false;
			
			
			//给a标签加一个类好加点击事件
			$config['anchor_class']="class = ajax_fpage ";
			$config['query_string_segment'] ='p';
			$this->pagination->initialize($config);
			//强制跳转页码
			$pages= $this->pagination->create_links();
			//$this->pagination->cur_page = (int)$page;
			$list=$this->db->where($where)->order_by("sort_id","desc")->
						limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
			
			//$list=$this->db->order_by('sort_id','desc')->get_where('article',array('cid'=>4,'ctype'=>$nav[0]['id']))->result_array();
		}
	}
	
}else{

	if(!empty($sec)){
		$page=!empty($_GET['p'])?$_GET['p']:1;
		$this->load->library('pagination');
		$config['base_url'] =SITE_URL.('product_ajax?sec='.$sec);
		$where=array('audit'=>1,'ctype'=>$sec,'cid'=>4);
		$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
		// var_dump($this->db->last_query());
		$config['per_page'] = 12;
		$config['uri_segment'] = 3;//页码所在URI段
		//将链接改为get方式
		$config['enable_query_strings']=TRUE;
		$config['page_query_string']=TRUE;
		$config['use_page_numbers'] = TRUE;
		$config['cur_tag_open']= '<a class="active">';
		$config['cur_tag_close']='</a>';
		$config['full_tag_open'] = '<div class="page">';
		$config['full_tag_close'] = '</div>';
		
		$config['num_links']=5;
		$config['prev_link']='<';
		$config['next_link']='>';
		$config['num_tag_open']='';
		$config['num_tag_close']='';
		$config['prev_tag_open']='';
		$config['prev_tag_close']='';
		$config['next_tag_open']='';
		$config['next_tag_close']='';
		$config['last_link'] = false;
		$config['first_link']= false;
		
		//给a标签加一个类好加点击事件
		$config['anchor_class']="class = ajax_fpage ";
		$config['query_string_segment'] ='p';
		$this->pagination->initialize($config);
		//强制跳转页码
		$pages= $this->pagination->create_links();
		//$this->pagination->cur_page = (int)$page;
		$list=$this->db->where($where)->order_by("sort_id","desc")->
					limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
		
		//$list=$this->db->order_by('sort_id','desc')->get_where('article',array('cid'=>4,'ctype'=>$sec))->result_array();
		$con=$this->db->get_where('coltypes',array('cid'=>4,'id'=>$sec,'depth'=>1))->row_array();
		if(!empty($con)){
			$nav=$this->db->order_by('sort_id','asc')->get_where('coltypes',array('cid'=>4,'fid'=>$con['fid'],'depth'=>1))->result_array();
		}
		
		
		
	}else{
		if(!empty($_GET['one'])){
			$one=$_GET['one'];
			$nav=$this->db->order_by('sort_id','asc')->get_where('coltypes',array('cid'=>4,'fid'=>$one,'depth'=>1))->result_array();
			if(!empty($nav)){
				$sec=$nav[0]['id'];
				$page=!empty($_GET['p'])?$_GET['p']:1;
				$this->load->library('pagination');
				$config['base_url'] =SITE_URL.('product_ajax?sec='.$sec);

				$where=array('audit'=>1,'ctype'=>$sec,'cid'=>4);

				$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
				$config['per_page'] = 12;
				$config['uri_segment'] = 3;//页码所在URI段
				//将链接改为get方式
				$config['enable_query_strings']=TRUE;
				$config['page_query_string']=TRUE;
				$config['use_page_numbers'] = TRUE;
				$config['cur_tag_open']= '<a class="active">';
				$config['cur_tag_close']='</a>';
				$config['full_tag_open'] = '<div class="page">';
				$config['full_tag_close'] = '</div>';
				
				$config['num_links']=5;
				$config['prev_link']='<';
				$config['next_link']='>';
				$config['num_tag_open']='';
				$config['num_tag_close']='';
				$config['prev_tag_open']='';
				$config['prev_tag_close']='';
				$config['next_tag_open']='';
				$config['next_tag_close']='';
				$config['last_link'] = false;
				$config['first_link']= false;
				
				//给a标签加一个类好加点击事件
				$config['anchor_class']="class = ajax_fpage ";
				$config['query_string_segment'] ='p';
				$this->pagination->initialize($config);
				//强制跳转页码
				$pages= $this->pagination->create_links();
				//$this->pagination->cur_page = (int)$page;
				$list=$this->db->where($where)->order_by("sort_id","desc")->
							limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
							// var_dump($list);exit;
				//$list=$this->db->order_by('sort_id','desc')->get_where('article',array('cid'=>4,'ctype'=>$nav[0]['id']))->result_array();
			}else{
				$sec=$this->input->get('sec',TRUE);
				$page=!empty($_GET['p'])?$_GET['p']:1;
				$this->load->library('pagination');
				$config['base_url'] =SITE_URL.('product_ajax?sec='.$sec.'&one='.$one);

				$where=array('audit'=>1,'ctype'=>$one,'cid'=>4);

				$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
				$config['per_page'] = 12;
				$config['uri_segment'] = 3;//页码所在URI段
				//将链接改为get方式
				$config['enable_query_strings']=TRUE;
				$config['page_query_string']=TRUE;
				$config['use_page_numbers'] = TRUE;
				$config['cur_tag_open']= '<a class="active">';
				$config['cur_tag_close']='</a>';
				$config['full_tag_open'] = '<div class="page">';
				$config['full_tag_close'] = '</div>';
				
				$config['num_links']=5;
				$config['prev_link']='<';
				$config['next_link']='>';
				$config['num_tag_open']='';
				$config['num_tag_close']='';
				$config['prev_tag_open']='';
				$config['prev_tag_close']='';
				$config['next_tag_open']='';
				$config['next_tag_close']='';
				$config['last_link'] = false;
				$config['first_link']= false;
				
				//给a标签加一个类好加点击事件
				$config['anchor_class']="class = ajax_fpage ";
				$config['query_string_segment'] ='p';
				$this->pagination->initialize($config);
				//强制跳转页码
				$pages= $this->pagination->create_links();
				//$this->pagination->cur_page = (int)$page;
				$list=$this->db->where($where)->order_by("sort_id","desc")->limit($config['per_page'],($page-1)*$config['per_page'])->get('article')->result_array();
			}


		}else{
			$list='';
			$nav='';
			
		}
	}
}

// if(empty($_GET['p'])){
// 	$page=1;
// }else{
// 	$page= $_GET['p'];
// }


?>

<div class="w1190" style="z-index: 110;">
	<div class="p-first-down">
		<div class="p-subnav">
		<?php if(!empty($nav)):?>
		<?php foreach($nav as $k=>$v):?>
			<div class="js-pro-btn2" sec-id="<?php echo $v['id']?>"><p class="text"><?php echo $v['title'];?></p></div>
		<?php endforeach;?>
		<?php endif;?>
		</div>
	</div>
</div>
<?php if(!empty($list)):?>
<div class="w1190 goods">
	<div class="list-box f-cb" style="width:110%;">
	<?php foreach($list as $k=>$v):?>
		<a href="<?php echo site_url('product/info/'.$v['id']); ?>">
			<div class="fl goods-frame">
				<img src="<?php echo UPLOAD_URL.tag_photo($v['photo']); ?>" />
				<img class="text-img-sw" src="<?php echo static_file('web/img/text-img-sw.png'); ?>">
				<div class="goods-name"><?php echo msubstr(str_replace('&nbsp;','',trim(strip_tags($v['title']))),0,18);?></div>
				<div class="goods-state">SHOP&nbsp;NOW</div>
			</div>
		</a>
	<?php endforeach;?>
	</div>
</div>
<?php echo $pages;?>
<?php endif;?>
<!-- <div class="paging"></div> -->
<script type="text/javascript">
$('.p-subnav .js-pro-btn2:last').find('.text').css('border','none');
</script>